home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / pascal / totdoc.zip / CHAPT8.TXT < prev    next >
Text File  |  1991-02-11  |  17KB  |  396 lines

  1.                                                                       Displaying
  2.                                                                         Messages
  3.                                                                                &
  4.                                                                          Prompts
  5.  
  6.  
  7.  
  8.          "As Miss America, my goal is to bring peace to the entire world and
  9.          then to get my own apartment."
  10.  
  11.                                                                         Jay Leno
  12.  
  13.  
  14.  
  15. Introduction
  16.          The totMSG unit includes a variety of easy-to-use objects for display-
  17.          ing messages and prompts. A message is simply a pop-up window which is
  18.          displayed until the user presses [KEYCAP], [KEYCAP], or clicks the
  19.          mouse on the close icon/button. Similarly, a prompt is a pop-up window,
  20.          but the user must select one of the options displayed at the bottom of
  21.          the window. A prompt window can have two or three buttons. The buttons
  22.          come in two varieties: strip-buttons like the ones used in the Turbo
  23.          Pascal IDE, and box-buttons like the ones used by PC Tools and the
  24.          Norton Utilities.
  25.  
  26.  
  27.  
  28. The Object Hierarchy
  29.          Figure 8.1 illustrates the object hierarchy for the totMSG unit. The
  30.          base (or primitive) object is BaseMessageOBJ, and all the other messag-
  31.          ing objects descend from it. You should never declare an instance of
  32.          type BaseMessageOBJ, as it is an abstract object. Use one of the
  33.          following four descendant objects:
  34.  
  35.          MessageOBJ         This is the basic message displaying object. Between
  36.                             one and twenty lines of text can be displayed in a
  37.                             moveable window. At the bottom of the window is a
  38.                             single strip-button, which defaults to the text
  39.                             "OK".  The user removes the window by clicking the
  40.                             mouse on the button or close icon, or by pressing
  41.                             [KEYCAP] or [KEYCAP].
  42.          ButtonMessageOBJ   This object is a descendant of MessageOBJ and
  43.                             operates in the same way. The only difference is
  44.                             that the button is a box-button.
  45.  
  46.          PromptOBJ          The PromptOBJ object is descendant from the BaseMes-
  47.                             sageOBJ, and should be used when you want to prompt
  48.                             the user to choose a specific option. A message is
  49.                             displayed in a moveable window, and two or three
  50.                             strip-buttons are displayed. The user removes the
  51.                             window by clicking on one of the buttons or the
  52.                             close icon, or by pressing [KEYCAP]. The buttons can
  53.  
  54. 8-2                                                                 User's Guide
  55. --------------------------------------------------------------------------------
  56.  
  57.                             be selected in one of three ways: clicking on the
  58.                             button, tabbing to a button and pressing [KEYCAP],
  59.                             or pressing a button hotkey.
  60.  
  61.          ButtonPromptOBJ    This objects displays box-buttons, but in all other
  62.                             aspects it operates like PromptOBJ.
  63.  
  64.  
  65. Figure 8.1                                                             [PICTURE]
  66. Message
  67. Object Hierarchy
  68.          This combination of objects provides you with ways of displaying
  69.          single, double and triple button messages, using strip- or box-buttons.
  70.          The decision to use strip- or box-buttons is solely cosmetic. The
  71.          strip-buttons are more "elegant", but the box-buttons are larger and
  72.          easier to select with the mouse.
  73.  
  74. Common Methods
  75.  
  76.          Since all the objects are derived from the BaseMessageOBJ, they share a
  77.          set of common methods. The following three methods can (and should) be
  78.          used with any of the messaging objects:
  79.  
  80.          Init(Style:byte;Tit:string);
  81.  
  82.          The Init method is passed two parameters. The first is the window box
  83.          style, and the second, the window title. Refer to 5-7 for a discussion
  84.          of box styles and titles. As always, this method must be called before
  85.          any other.
  86.  
  87.          AddLine(Str:string);
  88.  
  89.          Call this method to add a line of text to the method. For example, if
  90.          you want to display five lines of text, call AddLine five times. Up to
  91.          twenty lines of text can be displayed in a message. The text should be
  92.          no more than seventy characters long. The first line of text is always
  93.          displayed on the first line of the window, i.e. immediately below the
  94.          title. To force a space between the title and the text, call AddLine
  95.          with an empty string, e.g. AddLine('');.  Similarly, the buttons are
  96.          positioned directly below the last line of text. Just call Addline with
  97.          an empty string to force a gap between the text and the buttons. The
  98.          Toolkit automatically computes the size of the message window based on
  99.          the number of lines added, the width of the longest line, and the style
  100.          of button selected.
  101.  
  102.          WinForm: WinFormPtr;
  103.  
  104.  
  105.  
  106. Messages & Prompts                                                           8-3
  107. --------------------------------------------------------------------------------
  108.  
  109.          This function method returns a pointer to the Toolkit WinFormOBJ object
  110.          which is used to manage user input while the message is being dis-
  111.          played. You can use this function method to directly access the WinFor-
  112.          mOBJ methods with the following syntax: WinForm^.method. Refer to
  113.          chapter 11: Controlling User Input for a full discussion of WinFormOBJ.
  114.  
  115.  
  116.  
  117.            Note: the colors used by the message objects are derived from two
  118.            sources. The display of the window border and the message text is
  119.            controlled by the window settings used by the WinForm object.
  120.            Although this object is not discussed until chapter 11, it is
  121.            worthwhile noting that you can modify the window colors with the
  122.            following method call: WinForm^.Win^.SetColors. For example:
  123.                     MyMsg.WinForm^.Win^.SetColors(23,31,30,28);
  124.            The display color of the message buttons are controlled by the
  125.            default colors set in the global instance IOTOT. The following
  126.            method can be used to change the button colors: IOTOT^.SetColBut-
  127.            ton. For example:
  128.                     IOTOT^.SetColButton(32,46,47,46);
  129.            Refer to chapter 11 for further information.
  130.  
  131.  
  132.  
  133. 8-4                                                                 User's Guide
  134. --------------------------------------------------------------------------------
  135.  
  136.          Done;
  137.  
  138.          This method disposes of all the memory used by the object instance, and
  139.          should always be called.
  140.  
  141.  
  142.  
  143. Simple Messages
  144.  
  145.          The MessageOBJ and ButtonMessageOBJ objects are used for displaying
  146.          simple messages, i.e. an informational message where you don't want the
  147.          user to make a selection. The user just reads the message and removes
  148.          it.
  149.          Both these objects include the following method:
  150.  
  151.  
  152.          Show;
  153.          This method instructs the Toolkit to display the message window.
  154.  
  155.  
  156.          Listed below is the (by now familiar) example DEMMS1.PAS, followed by
  157.          figure 8.2 which illustrates the generated display.
  158.          program DemoMessageOne;
  159.          {demms1 - simple message}
  160.  
  161.          Uses DOS, CRT,
  162.               totFAST, totMSG;
  163.          Var
  164.             MsgWin : MessageOBJ;
  165.  
  166.          begin
  167.             Screen.Clear(white,'░'); {paint the screen}
  168.             with MsgWin do
  169.             begin
  170.                Init(1,' Message ');
  171.                AddLine('');
  172.                AddLine('The message unit provides a');
  173.                AddLine('very easy way of displaying');
  174.                AddLine('pop-up messages in a move-');
  175.                AddLine('able window.');
  176.                AddLine('');
  177.                Show;
  178.                Done;
  179.             end;
  180.          end.
  181.  
  182. Figure 8.2                                                              [SCREEN]
  183. A Simple Message
  184.  
  185.  
  186.  
  187. Messages & Prompts                                                           8-5
  188. --------------------------------------------------------------------------------
  189.  
  190.          By simply changing the instance declaration to MsgWin: ButtonMessa-
  191.          geOBJ; the message will be displayed using a box-button. The example
  192.          DEMMS2.PAS contains this simple modification, and the output is shown
  193.          in figure 8.3.
  194.  
  195.  
  196. Figure 8.3                                                              [SCREEN]
  197. A Simple Message
  198. with a Box-Button
  199.  
  200.  
  201.          By default, the button text is "OK", and the button has a hotkey of
  202.          "O", i.e. the user can select the button, and thereby clear the mes-
  203.          sage, by pressing [KEYCAP]. The following method provides a way of
  204.          changing the button text and hotkey:
  205.  
  206.  
  207.          SetOption(Str:string;Hotkey:word);
  208.          This method changes the button settings. The first parameter identifies
  209.          the text to be displayed, and the second is the keycode of the hotkey
  210.          used to select the button. A code of 0 (zero) signifies no hotkey.
  211.  
  212.  
  213.  
  214.            Note: the totIO1 unit includes a constant MaxButtonWidth which
  215.            sets the maximum button string length. By default, the maximum
  216.            string length is 30. However, it can be modified. This subject is
  217.            fully addressed in chapter 11: Controlling User Input.
  218.  
  219.  
  220.  
  221.          Listed below is the example file DEMMS3, which is similar to
  222.          DEMMS1.PAS. The only difference is that the SetOption method was used
  223.          to change the default button settings. Notice that the "~" symbol is
  224.          used to highlight specific letters in the button text. This concept was
  225.          discussed in chapter 5: Writing to the Screen on page 5-3 (WriteHi).
  226.  
  227.  
  228.          program DemoMessageThree;
  229.          {demms3 - using SetOption to change button text}
  230.  
  231.          Uses DOS, CRT,
  232.               totFAST, totMSG;
  233.          Var
  234.             MsgWin : MessageOBJ;
  235.  
  236.  
  237.  
  238. 8-6                                                                 User's Guide
  239. --------------------------------------------------------------------------------
  240.  
  241.          begin
  242.             Screen.Clear(white,'░'); {paint the screen}
  243.             with MsgWin do
  244.             begin
  245.                Init(1,' Message ');
  246.                AddLine('');
  247.                AddLine('The message unit provides a');
  248.                AddLine('very easy way of displaying');
  249.                AddLine('pop-up messages in a move-');
  250.                AddLine('able window.');
  251.                AddLine('');
  252.                SetOption(' A very ~l~ong button ',76);
  253.                Show;
  254.                Done;
  255.             end;
  256.          end.
  257.  
  258.  
  259. Figure 8.4                                                              [SCREEN]
  260. Changing the
  261. Button Text
  262.  
  263.  
  264. Multi-Button Prompts
  265.  
  266.          The PromptOBJ and ButtonPromptOBJ objects are used for displaying mes-
  267.          sages with two or three buttons. The user removes a message by select-
  268.          ing one of the buttons.
  269.          By default, Prompt objects have two buttons, with the text "OK" and
  270.          "Cancel". The function method Show is used to instruct the Toolkit to
  271.          display the message. This function returns a member of the enumerated
  272.          type tAction to indicate which option the user selected. The enumerated
  273.          type tAction is declared in the totIO1 unit as follows:
  274.  
  275.                   Type
  276.                   tAction = (None,NextField,PrevField,Finished,Escaped,
  277.                              Refresh,Signal,Enter,Help,Stop1,Stop2,
  278.                              Stop3,Stop4,Stop5,Stop6,Stop7,Stop8,Stop9);
  279.          The majority of these members are for use in full screen editing
  280.          (discussed in chapter 11), and the only ones that should be used with
  281.          messaging are: Finished, Escaped, or Stop1 through Stop9. By default,
  282.          if the user selects the OK button, the member "Finished" is returned,
  283.          and if the user selects the Cancel button or presses [KEYCAP], the
  284.          member "Escaped" is returned. The syntax of the Show method is as
  285.          follows:
  286.  
  287.  
  288.          Show:tAction;
  289.  
  290.  
  291.  
  292. Messages & Prompts                                                           8-7
  293. --------------------------------------------------------------------------------
  294.  
  295.          Displays the message window, and returns a member of the enumerated
  296.          type tAction, to indicate which button the user selected.
  297.  
  298.  
  299.          The on-disk example DEMMS4.PAS illustrates how to display a PromptOBJ
  300.          using the default button settings. The following method, SetOption,
  301.          provides a way of changing the button text and hotkeys:
  302.  
  303.          SetOption(ID:byte; Str:StringBut;Hotkey:word;Act:tAction);
  304.  
  305.          The first parameter indicates which button you want to define, and can
  306.          have a value of 1, 2 or 3. The second parameter is the text to be
  307.          displayed in the button. The third button is a key code identifying a
  308.          hotkey which can be used to select the button. Finally, the fourth
  309.          parameter is a member of the enumerated type tAction. This is the mem-
  310.          ber which will be returned by the method Show if this button is
  311.          selected. Only use the members Finished, Escaped, or Stop1 through
  312.          Stop9, and assign a different value to each button!
  313.  
  314.          Remember that the objects also have the methods Init, Done and AddLine
  315.          which were discussed previously. Listed below is the demo program
  316.          DEMMS5.PAS which illustrates the use of the SetOption method. Figure
  317.          8.5 illustrates the resultant display.
  318.  
  319.          program DemoMessageFive;
  320.          {demms5 - two strip-buttons with specific text}
  321.          Uses DOS, CRT,
  322.               totFAST, totMSG, totIO1;
  323.  
  324.          Var
  325.             MsgWin : PromptOBJ;
  326.             ActionCode: tAction;
  327.          begin
  328.             Screen.Clear(white,'░'); {paint the screen}
  329.             with MsgWin do
  330.             begin
  331.                Init(1,' Warning ');
  332.                AddLine('');
  333.                AddLine(' The file already exists on disk, and ');
  334.                AddLine(' the contents will be over-written.');
  335.                AddLine('');
  336.                SetOption(1,' ~P~roceed ',80,Finished);
  337.                SetOption(2,' ~A~bort ',65,Escaped);
  338.                ActionCode := Show;
  339.                Done;
  340.             end;
  341.          end.
  342.  
  343.  
  344.  
  345. 8-8                                                                 User's Guide
  346. --------------------------------------------------------------------------------
  347.  
  348. Figure 8.5                                                              [SCREEN]
  349. Using PromptOBJ
  350.  
  351.  
  352.          The message could have been generated with box-buttons simply by using
  353.          the object ButtonPromptOBJ instead of PromptOBJ - see the on-disk exam-
  354.          ple DEMMS6.PAS.
  355.  
  356.  
  357.          The SetOption method is also the way to add a third button. Just pass a
  358.          button ID of 3 and a third button will be displayed. The listing of
  359.          DEMMS7.PAS followed by figure 8.6 illustrates this technique:
  360.  
  361.          program DemoMessageSeven;
  362.          {demms7 - three buttons}
  363.          Uses DOS, CRT,
  364.               totFAST, totMSG, totIO1;
  365.  
  366.          Var
  367.             MsgWin : PromptOBJ;
  368.             ActionCode: tAction;
  369.          begin
  370.             Screen.Clear(white,'░'); {paint the screen}
  371.             with MsgWin do
  372.             begin
  373.                Init(1,' Warning ');
  374.                AddLine('');
  375.                AddLine(' The file already exists on disk, and ');
  376.                AddLine(' the contents will be over-written.');
  377.                AddLine('');
  378.                SetOption(1,' ~P~roceed ',80,Finished);
  379.                SetOption(2,' ~A~bort ',65,Escaped);
  380.                SetOption(3,' ~H~elp ',72,Stop1);
  381.                ActionCode := Show;
  382.                Done;
  383.             end;
  384.          end.
  385.  
  386.  
  387.  
  388.  
  389. Figure 8.6                                                              [SCREEN]
  390. Using Three
  391. Buttons
  392.  
  393.  
  394.          The on-disk example DEMMS8.PAS shows how to use ButtonPromptOBJ to dis-
  395.          play three box-buttons.
  396.